#ifndef MATERIAL_H_
#define MATERIAL_H_

#include "Color.h"

struct Material
{
	Material(Color a = Color(0.5f,0.5f,0.5f),
					 Color d = Color(0.5f,0.5f,0.5f),
					 Color s = Color(0.8f,0.8f,0.8f),
					 float sp = 8,
					 float r = 0.0f,
					 float t = 0.0f)
					 : _ambient(a), _diffuse(d), _specular(s), _specularPower(sp), _reflectance(r), _transparency(t)
	{}

	Color _ambient;
	Color _diffuse;
	Color _specular;
	float _specularPower;
	float _reflectance;
	float _transparency;

	float _tmpSpecPower;

	inline void Zero()
	{
		_ambient.zero();
		_diffuse.zero();
		_specular.zero();
		_specularPower = 0;
		_reflectance = 0.0f;
		_transparency = 0.0f;

		_tmpSpecPower = 0.0f;
	}

	inline void MultiplyAndAdd(const Material & m, float scalar)
	{
		_ambient += m._ambient * scalar;
		_diffuse += m._diffuse * scalar;
		_specular += m._specular * scalar;
		_tmpSpecPower += float(m._specularPower) * scalar;
		_reflectance += m._reflectance * scalar;
		_transparency += m._transparency * scalar;
	}

	inline void operator /= (float div)
	{
		float rDiv = 1.0f / div;
		_ambient *= rDiv;
		_diffuse *= rDiv;
		_specular *= rDiv;
		_specularPower = _tmpSpecPower * rDiv;
		_reflectance *= rDiv;
		_transparency *= rDiv;
	}
};


#endif
